<template>
  <div style="width:1200px">
    <div class="xian"></div>
    <el-card class="box-card">
      <el-form ref="form" :model="form" label-width="100px" size="small">
        <el-form-item label="旧密码">
          <el-input v-model="form.oldPassword" maxlength="500" placeholder="请输入旧密码"></el-input>
        </el-form-item>
        <el-form-item label="新密码">
          <el-input v-model="form.newPassword" maxlength="500" placeholder="请输入新密码"></el-input>
        </el-form-item>
        <el-form-item label="确认新密码">
          <el-input v-model="form.newPasswordAgen" maxlength="500" placeholder="再次输入新密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit()">确定</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { updatePassword } from "@/api/settings"
export default {
  name: "updatepassWord",
  data() {
    return {
      form: {}
    }
  },
  methods: {
    submit() {
        if(this.form.oldPassword == ''){
          this.$message.error("请输入旧密码!")
          return false;
        }
        if(this.form.newPassword == ''){
          this.$message.error("请输入新密码!")
          return false;
        }

        if(this.form.newPasswordAgen == ''){
          this.$message.error("请再次输入新密码!")
          return false;
        }

        if(this.form.newPassword != this.form.newPasswordAgen){
          this.$message.error("两次密码不匹配!")
          return false;
        }

      updatePassword(this.form.oldPassword,this.form.newPassword).then(data => {
        if (data.result) {
          this.$message({
            message: "设置成功！",
            type: "success"
          })
        } else {
          this.$message.error("设置失败!" + data.errMsg)
        }
      })
    }
  }
}
</script>
